package DatabaseAccess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MyConnection {
    private static MyConnection instance;

    public static MyConnection getInstance() {
        if (instance == null) {
            instance = new MyConnection();
        }

        return instance;
    }

    Connection con = null;
    String driver = "";
    String urlDriver = "";
    String serverName = "";
    String databaseName = "";
    String username = "";
    String password = "";

    public MyConnection() {
        driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        urlDriver = "jdbc:sqlserver://";
        serverName = "localhost";
        databaseName = "ResultDeclarationBoard";
        username = "sa";
        password = "123456";
    }

    public Connection getConnection() {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException ex) {
            System.out.println("Load driver error!");
        }

        try{
            con = DriverManager.getConnection(urlDriver + serverName + ";databaseName=" + databaseName + ";user=" + username + ";password=" + password);
        }catch(SQLException ex){
            System.out.println("Connecting false!");
        }

        return con;
    }
}
